﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Data.SqlClient;
using Conexion;


namespace Autorizacion_facturas_caja
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        ClsConexion conexion = new ClsConexion();
        string usuario, pass;
        private void button1_Click(object sender, EventArgs e)
        {
           /* if (conexion.entrar("select * from seg_usuariosppal where usuario='" + textBox2.Text.Trim() + "' and contraseña='" + textBox1.Text.Trim() + "'"))
            {
                conexion.ConectarBD();
                SqlCommand id = new SqlCommand("select usr_id from seg_usuariosppal where usuario='" + textBox2.Text.Trim() + "' and contraseña='" + textBox1.Text.Trim() + "'", conexion.conectar);

                conexion.Id = int.Parse(id.ExecuteScalar().ToString());
                conexion.Usuario = textBox2.Text;
                conexion.Contraseña = textBox1.Text;                
                conexion.conectar.Close();
                this.Close();
            }
            else { toolStripStatusLabel1.Text = "Datos Incorrectos"; }*/
            if (ValidarUsuario())
            { 
                conexion.Usuario = textBox2.Text;
                conexion.Contraseña = textBox1.Text;
                conexion.conectar.Close();
                Close();
            } else { toolStripStatusLabel1.Text = "Datos Incorrectos"; }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string ipLocal = (Dns.Resolve(Dns.GetHostName())).AddressList[0].ToString();
            switch (ipLocal)
            {
                case "192.168.0.112":
                    textBox2.Text = "roberto.navarro";
                    textBox1.Text = "JD26wspc";
                    break;
                case "10.100.100.112":
                    textBox2.Text = "roberto.navarro";
                    textBox1.Text = "JD26wspc";
                    break;
                case "192.168.0.29":
                    textBox2.Text = "sa";
                    textBox1.Text = "hermosillo";
                    break;
            }
        }

        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                button1_Click(sender, e);
            }
        }
        private bool ValidarUsuario()
        {
            string pass2;
            usuario = textBox2.Text.Trim();
            pass = textBox1.Text.Trim();
           
           
            pass2 = Usuarios(usuario);
            if (pass2 == pass) { return true; }
 
           return false;
        }
        private string Usuarios(string usuario)
        {
            string pass1;
            switch (usuario)
            {
                case "admin":
                    pass1 = "admin";
                    return pass1;
                //break;
                case "test":
                    pass1 = "test";
                    return pass1;
                //break;
                case "normal":
                    pass1 = "normal";
                    return pass1;
                //break;
            }
            return "falso";
        }

    }
}
